package cn.hongwei.controller;

import cn.hongwei.pojo.IndexPopup;
import cn.hongwei.service.IndexPopupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Great
 * @email 1224028994@qq.com
 */
@RestController
@RequestMapping("index/popup")
public class IndexPopupController {

    @Autowired
    private IndexPopupService popupService;

    //新增弹窗
    @PostMapping("save")
    public void saveIndexPopup(@RequestBody IndexPopup indexPopup){
        popupService.saveIndexPopup(indexPopup);
    }

    //根据id更新弹窗
    @PutMapping("update")
    public void updateIndexPopup(@RequestBody IndexPopup indexPopup){
        popupService.updateIndexPopup(indexPopup);
    }

    @DeleteMapping("delete")
    public void deleteIndexPopup(@RequestParam("id") Long id){
        popupService.deleteById(id);
    }

    /**
     * 根据用户id展示所有弹窗
     * @param userNo
     * @return
     */
    @GetMapping("showAllPopups")
    public List<IndexPopup> showAllPopups(@RequestParam("userNo") String userNo){
        return popupService.showAllPopups(userNo);
    }
}
